package com.solotiger.geographic;

import android.app.Application;

import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.imagepipeline.backends.okhttp3.OkHttpImagePipelineConfigFactory;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.solotiger.geographic.db.DatabaseManger;
import com.solotiger.geographic.factory.OKHttpFactory;

import java.lang.ref.WeakReference;


public class GeoApplication extends Application {

    private static WeakReference<GeoApplication> mInstance;

    public static GeoApplication getInstance() {
        return mInstance == null ? null : mInstance.get();
    }


    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = new WeakReference<>(this);

        ImagePipelineConfig config = OkHttpImagePipelineConfigFactory
                .newBuilder(this, OKHttpFactory.INSTANCE.getOkHttpClient())
                .setDownsampleEnabled(true)
                .build();
        Fresco.initialize(this, config);
        DatabaseManger.ME.init(this);
    }

    @Override
    public void onTerminate() {
        super.onTerminate();
        DatabaseManger.ME.close();
    }
}
